import { forwardRef, useRef } from "react"

const Son = forwardRef((props, ref) => {
    return <input type="text" ref={ref}></input>
})

const practice3 = () => {

    const sonRef = useRef(null)

    const showRef = () => {
        // 获取子组件dom对象
        console.log(`output->`, sonRef)
        sonRef.current.focus()
    }

    return (
        <div>
            <div>forwardRef</div>
            <Son ref={sonRef} />
            <button onClick={showRef}>focus</button>
        </div>
    )
}

export default practice3